<?php
// 文件名 api/controller/Activity.php
namespace app\api\controller;

use app\common\controller\Api;


/**
 * 活动接口
 */
class Activity extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /** 
     * 活动列表
     *
     */
    public function index()
    {
        $category = input('param.category')?input('param.category'):'rec';
        $per_page = input('param.per_page')?input('param.per_page'):6;
        $keywords = input('param.keywords')?input('param.keywords'):'';
        $map = [];
        if($category == 'rec'){
            $map['is_rec'] = 1;
        }else{
            $map['category_id'] = $category;
        }
        if($keywords!=''){
            $map['title'] =['like','%'.$keywords.'%'];
        }
        $data = model('Activity')
            ->where($map)
            ->field('content',true) // 过滤content字段
            ->order('weigh desc') // 排序字段
            ->paginate($per_page);

        $this->success('查询成功！', $data);    
    }

    // 活动详情
    public function detail(){
        if(!input('?param.id')){
            $this->error('参数不正确！');   
        }
        $data = model('Activity')
            ->where('id',input('id'))
            ->find();

        $this->success('查询成功！', $data);    
    }
}
